<?php

class SQL_DB {
	var $sqlite;
	
	function __construct($file) {
		if (!file_exists($file)) {
			throw new Exception('Given database file not found.');
		}
		$this->sqlite = new SQLite3($file);
		if($this->sqlite->lastErrorCode()) {
			die($this->sqlite->lastErrorMsg());
		}
		
		$res = $this->sqlite->query("SELECT name FROM sqlite_master");
		while ($row = $res->fetchArray()) {
			var_dump($row);
		}
		
	}
	
	public function do_query($query) {
		return $this->sqlite->query($query);
	}
	public function random_result($results) {
		$num_rows = $results->numRows();
		$row = mt_rand(0, $num_rows-1);
		$results->seek($row);
		return $results->fetch();
	}
	public function escape_string($str) {
		return  $this->sqlite->escapeString($str);
	}
}
$db = new SQL_DB("bd.db");

?>